import Vue from 'vue'
import Router from 'vue-router'
import departmentRouter from '@/router/modules/department'
import approvalRouter from '@/router/modules/approval'
import employeeRouter from '@/router/modules/employee'
import permissionRouter from '@/router/modules/permission'
import socialRouter from '@/router/modules/social'
import salaryRouter from '@/router/modules/salary'
import roleRouter from '@/router/modules/role'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: '', // 二级路由地址为空时表示 /dashboard显示一级路由+二级路由 也就是默认二级路由
        component: () => import('@/views/dashboard'),
        hidden: false,
        name: 'dashboard', // 可以用来跳转 也可以标记路由
        meta: {
          // 路由元信息（用来存储数据的，比如图标，名称）
          icon: 'dashboard', // 菜单的图标
          title: '首页' // 菜单的标题
        }
      }
    ]
  }
]
// 动态路由
export const asyncRouter = [
  departmentRouter,
  roleRouter,
  employeeRouter,
  permissionRouter,
  approvalRouter,
  salaryRouter,
  socialRouter
]
const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({y: 0}),
  routes: constantRoutes // 默认用于静态路由
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
